#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
   int data;          // 结点数据域
   struct node *next; // 结点指针域(自己本身)
} ListNode;

typedef ListNode *LinkList;

void pushA(ListNode **n, int x)
{
   ListNode *head = (ListNode *)malloc(sizeof(ListNode));
   head->data = x;
   head->next = (*n);
   (*n) = head;
};

// 由于结点类型是指针类型变量，所以赋值给下个结点的类型也必须是指针类型变量
void pushE(LinkList L, int x)
{
   ListNode *head = (ListNode *)malloc(sizeof(ListNode));
   head->data = x;
   printf("inner===>point=%p, value=%d\n", L, L == NULL ? -1 : L->data);
   // L 是结点存储的地址，即指针变量存储的地址
   head->next = L;
   L = head;
   printf("assignment===>point=%p, value=%d\n", L, L == NULL ? -1 : L->data);
}

void push(LinkList *L, int x)
{
   ListNode *head = (ListNode *)malloc(sizeof(ListNode));
   head->data = x;
   printf("inner===>point=%p, value=%d\n", (*L), (*L) == NULL ? -1 : (*L)->data);
   // (*L)结点的值
   head->next = (*L);
   (*L) = head;
   printf("assignment===>point=%p, value=%d\n", (*L), (*L) == NULL ? -1 : (*L)->data);
};

int main(void)
{

   LinkList p = NULL;
   printf("===>point=%p, value=%d\n", p, p == NULL ? -1 : p->data);
   pushE(p, 1);
   pushE(p, 2);
   // ===>point=0x0, value=-1
   // inner===>point=0x0, value=-1
   // assignment===>point=0x100404080, value=1
   // inner===>point=0x0, value=-1
   // assignment===>point=0x100404090, value=2
   // ===>point=0x0, value=-1

   // ===>point=0x0, value=-1
   // inner===>point=0x0, value=-1
   // assignment===>point=0x100404080, value=1
   // inner===>point=0x100404080, value=1
   // assignment===>point=0x100404090, value=2
   // ===>point=0x100404090, value=2

   // push(&p, 1);
   // push(&p, 2);

   printf("===>point=%p, value=%d\n", p, p == NULL ? -1 : p->data);

   while (p != NULL)
   {
      printf("value=%d\n", p->data);
      p = p->next;
   }
}
